<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.3.0">
  <link rel="apple-touch-icon" sizes="180x180" href="https://www.hualigs.cn/image/6015799666530.jpg">
  <link rel="icon" type="image/png" sizes="32x32" href="https://www.hualigs.cn/image/6015799666530.jpg">
  <link rel="icon" type="image/png" sizes="16x16" href="https://www.hualigs.cn/image/6015799666530.jpg">
  <link rel="mask-icon" href="https://www.hualigs.cn/image/6015799666530.jpg" color="#222">
  <link rel="manifest" href="https://www.hualigs.cn/image/6015799666530.jpg">
  <meta name="msapplication-config" content="https://www.hualigs.cn/image/6015799666530.jpg">

<link rel="stylesheet" href="/diazang/css/main.css">


<link rel="stylesheet" href="/diazang/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"jue-xian.gitee.io","root":"/diazang/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":true,"scrollpercent":true},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="this my fifth week challenge!">
<meta property="og:type" content="article">
<meta property="og:title" content="csapplab_archlab">
<meta property="og:url" content="https://jue-xian.gitee.io/diazang/2021/05/06/csapplab-archlab/index.html">
<meta property="og:site_name" content="RUBIA">
<meta property="og:description" content="this my fifth week challenge!">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2021-05-06T13:26:16.000Z">
<meta property="article:modified_time" content="2021-05-06T13:37:41.646Z">
<meta property="article:author" content="H.R.P">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://jue-xian.gitee.io/diazang/2021/05/06/csapplab-archlab/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>csapplab_archlab | RUBIA</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/diazang/atom.xml" title="RUBIA" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/diazang/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">RUBIA</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/diazang/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/diazang/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/diazang/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/diazang/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/diazang/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
        <li class="menu-item menu-item-schedule">

    <a href="/diazang/schedule/" rel="section"><i class="fa fa-calendar fa-fw"></i>日程表</a>

  </li>
        <li class="menu-item menu-item-sitemap">

    <a href="/diazang/sitemap.xml" rel="section"><i class="fa fa-sitemap fa-fw"></i>站点地图</a>

  </li>
        <li class="menu-item menu-item-commonweal">

    <a href="/diazang/404/" rel="section"><i class="fa fa-heartbeat fa-fw"></i>公益 404</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://jue-xian.gitee.io/diazang/2021/05/06/csapplab-archlab/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="https://www.hualigs.cn/image/6015786be4309.jpg">
      <meta itemprop="name" content="H.R.P">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="RUBIA">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          csapplab_archlab
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2021-05-06 21:26:16 / 修改时间：21:37:41" itemprop="dateCreated datePublished" datetime="2021-05-06T21:26:16+08:00">2021-05-06</time>
            </span>

          
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/diazang/2021/05/06/csapplab-archlab/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/diazang/2021/05/06/csapplab-archlab/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>this my fifth week challenge!</p>
<a id="more"></a>

<p>第一次看wp都看的头大的东西</p>
<h1 id="PART-A"><a href="#PART-A" class="headerlink" title="PART A"></a>PART A</h1><p>任务：模拟examples.c完成三个函数的翻译：从c语言到Y86-64的汇编语言。</p>
<p>如下是例子.c文件中定义的一个链表</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;* linked list element *&#x2F;</span><br><span class="line">typedef struct ELE &#123;</span><br><span class="line">    long val;</span><br><span class="line">    struct ELE *next;</span><br><span class="line">&#125; *list_ptr</span><br></pre></td></tr></table></figure>
<p>以下是其测试得到的数据</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"># Sample linked list</span><br><span class="line">.align 8</span><br><span class="line">ele1:</span><br><span class="line">    .quad 0x00a</span><br><span class="line">    .quad ele2</span><br><span class="line">ele2:</span><br><span class="line">    .quad 0x0b0</span><br><span class="line">    .quad ele3</span><br><span class="line">ele3:</span><br><span class="line">    .quad 0xc00</span><br><span class="line">    .quad 0</span><br><span class="line"></span><br></pre></td></tr></table></figure>


<h2 id="sum-list"><a href="#sum-list" class="headerlink" title="sum_list"></a>sum_list</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;* sum_list - Sum the elements of a linked list *&#x2F;</span><br><span class="line">long sum_list(list_ptr ls)</span><br><span class="line">&#123;</span><br><span class="line">    long val &#x3D; 0;</span><br><span class="line">    while (ls) &#123;</span><br><span class="line">        val +&#x3D; ls-&gt;val;</span><br><span class="line">        ls &#x3D; ls-&gt;next;</span><br><span class="line">    &#125;</span><br><span class="line">    return val;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>这个是要求我们对链表进行迭代求和=-=</p>
<h4 id="sum-list-ys"><a href="#sum-list-ys" class="headerlink" title="sum_list.ys"></a>sum_list.ys</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><span class="line"># Execution begins at address 0 </span><br><span class="line">	.pos 0</span><br><span class="line">	irmovq stack, %rsp  	# Set up stack pointer</span><br><span class="line">	call main		# Execute main program</span><br><span class="line">	halt			# Terminate program </span><br><span class="line">	</span><br><span class="line"># 内存区域，存放数据&#x2F;链表之类</span><br><span class="line"># Sample linked list</span><br><span class="line">.align 8</span><br><span class="line">ele1:</span><br><span class="line">    .quad 0x00a</span><br><span class="line">    .quad ele2</span><br><span class="line">ele2:</span><br><span class="line">    .quad 0x0b0</span><br><span class="line">    .quad ele3</span><br><span class="line">ele3:</span><br><span class="line">    .quad 0xc00</span><br><span class="line">    .quad 0</span><br><span class="line"># END</span><br><span class="line"></span><br><span class="line">main:	</span><br><span class="line">	irmovq ele1,%rdi  #参数准备</span><br><span class="line">	call sum_list		# sum_list(ele1)</span><br><span class="line">	ret</span><br><span class="line"></span><br><span class="line"># long sum_list(long i)</span><br><span class="line"># ele1 in %rdi</span><br><span class="line">sum_list:	</span><br><span class="line">	xorq %rax,%rax           #val&#x3D;0</span><br><span class="line">loop:</span><br><span class="line">    mrmovq (%rdi),%r8 #读取node.val值到寄存器r8</span><br><span class="line">    addq %r8,%rax #将结果加到return val中</span><br><span class="line">    mrmovq 8(%rdi),%rdi</span><br><span class="line">    jmp test       #无条件跳转到test</span><br><span class="line">test:</span><br><span class="line">    andq %rdi,%rdi      </span><br><span class="line">    jne loop</span><br><span class="line">	ret                </span><br><span class="line"></span><br><span class="line"># Stack starts here and grows to lower addresses.</span><br><span class="line"># 这里自定义栈开始地址</span><br><span class="line">	.pos 0x200</span><br><span class="line">stack:</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>执行以下命令可以得到测试结果</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">.&#x2F;yas sum_list.ys .&#x2F;yis sum_list.yo</span><br></pre></td></tr></table></figure>


<h2 id="rsum-list"><a href="#rsum-list" class="headerlink" title="rsum_list"></a>rsum_list</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;* rsum_list - Recursive version of sum_list *&#x2F;</span><br><span class="line">long rsum_list(list_ptr ls)</span><br><span class="line">&#123;</span><br><span class="line">    if (!ls)</span><br><span class="line">	    return 0;</span><br><span class="line">    else &#123;</span><br><span class="line">        long val &#x3D; ls-&gt;val;</span><br><span class="line">        long rest &#x3D; rsum_list(ls-&gt;next);</span><br><span class="line">        return val + rest;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>


<p>和前面的sum_list大同小异，rsum这里先对node.val存储到了末尾才开始</p>
<p>addq %rbx,%rax</p>
<h4 id="rsum-list-ys"><a href="#rsum-list-ys" class="headerlink" title="rsum_list.ys"></a>rsum_list.ys</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></td><td class="code"><pre><span class="line"># Execution begins at address 0 </span><br><span class="line">	.pos 0</span><br><span class="line">	irmovq stack, %rsp  	# Set up stack pointer</span><br><span class="line">	call main		# Execute main program</span><br><span class="line">	halt			# Terminate program </span><br><span class="line">	</span><br><span class="line"># 内存区域，存放数据&#x2F;链表之类</span><br><span class="line"># Sample linked list</span><br><span class="line">.align 8</span><br><span class="line">ele1:</span><br><span class="line">    .quad 0x00a</span><br><span class="line">    .quad ele2</span><br><span class="line">ele2:</span><br><span class="line">    .quad 0x0b0</span><br><span class="line">    .quad ele3</span><br><span class="line">ele3:</span><br><span class="line">    .quad 0xc00</span><br><span class="line">    .quad 0</span><br><span class="line"># END</span><br><span class="line"></span><br><span class="line">main:	</span><br><span class="line">	irmovq ele1,%rdi  #参数准备</span><br><span class="line">	call rsum_list		# rsum_list(ele1)</span><br><span class="line">	ret</span><br><span class="line"></span><br><span class="line"># long rsum_list(long i)</span><br><span class="line"># ele1 in %rdi</span><br><span class="line">rsum_list:	</span><br><span class="line">    pushq %rbx          #自递归，需要保存目前的结果。其实rbx就是存了 上一个node.val</span><br><span class="line">	xorq %rax,%rax           #return val&#x3D;0</span><br><span class="line">    andq %rdi, %rdi</span><br><span class="line">    je finish</span><br><span class="line">    mrmovq (%rdi), %rbx  #当前的node.val</span><br><span class="line">    mrmovq 8(%rdi), %rdi #node &#x3D; node-&gt;next</span><br><span class="line">    call rsum_list</span><br><span class="line">    addq %rbx, %rax #在这里仍然会继续往下执行。</span><br><span class="line"></span><br><span class="line">finish:</span><br><span class="line">    popq %rbx            #</span><br><span class="line">	ret                  # Return</span><br><span class="line"></span><br><span class="line"># Stack starts here and grows to lower addresses.</span><br><span class="line"># 这里自定义栈开始地址</span><br><span class="line">	.pos 0x200</span><br><span class="line">stack:</span><br><span class="line"></span><br></pre></td></tr></table></figure>


<h2 id="copy-block"><a href="#copy-block" class="headerlink" title="copy_block"></a>copy_block</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;* copy_block - Copy src to dest and return xor checksum of src *&#x2F;</span><br><span class="line">long copy_block(long *src, long *dest, long len)</span><br><span class="line">&#123;</span><br><span class="line">    long result &#x3D; 0;</span><br><span class="line">    while (len &gt; 0) &#123;</span><br><span class="line">        long val &#x3D; *src++; &#x2F;&#x2F;两个语句：long val &#x3D; *src;src++;</span><br><span class="line">        *dest++ &#x3D; val;&#x2F;&#x2F;两个语句：*dest &#x3D; val;dest++</span><br><span class="line">        result ^&#x3D; val;&#x2F;&#x2F;update checksum</span><br><span class="line">        len--;</span><br><span class="line">    &#125;</span><br><span class="line">    return result;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">.align 8</span><br><span class="line"># Source block</span><br><span class="line">src:</span><br><span class="line">.quad 0x00a</span><br><span class="line">.quad 0x0b0</span><br><span class="line">.quad 0xc00</span><br><span class="line"># Destination block</span><br><span class="line">dest:</span><br><span class="line">.quad 0x111</span><br><span class="line">.quad 0x222</span><br><span class="line">.quad 0x333</span><br><span class="line"></span><br></pre></td></tr></table></figure>




<h4 id="copy-block-sy"><a href="#copy-block-sy" class="headerlink" title="copy_block.sy"></a>copy_block.sy</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br></pre></td><td class="code"><pre><span class="line"># Execution begins at address 0 </span><br><span class="line">	.pos 0</span><br><span class="line">	irmovq stack, %rsp  	# Set up stack pointer</span><br><span class="line">	call main		# Execute main program</span><br><span class="line">	halt			# Terminate program </span><br><span class="line">	</span><br><span class="line"># 内存区域，存放数据&#x2F;链表之类</span><br><span class="line">.align 8</span><br><span class="line"># Source block</span><br><span class="line">src:</span><br><span class="line">.quad 0x00a</span><br><span class="line">.quad 0x0b0</span><br><span class="line">.quad 0xc00</span><br><span class="line"># Destination block</span><br><span class="line">dest:</span><br><span class="line">.quad 0x111</span><br><span class="line">.quad 0x222</span><br><span class="line">.quad 0x333</span><br><span class="line"></span><br><span class="line">#END</span><br><span class="line">main:	</span><br><span class="line">	irmovq src,%rdi     #param1</span><br><span class="line">    irmovq dest,%rsi    #param2</span><br><span class="line">    irmovq $3,%rdx     #param3</span><br><span class="line">	call copy_block		# copy_block(src,dest,)</span><br><span class="line">	ret</span><br><span class="line"></span><br><span class="line"># long copy_block(long *src, long *dest, long len)</span><br><span class="line"># src in %rdi</span><br><span class="line"># dest in %rsi</span><br><span class="line"># 3 in %rdx</span><br><span class="line">copy_block:	</span><br><span class="line">    pushq %rbx</span><br><span class="line">    pushq %r9</span><br><span class="line">    pushq %r10</span><br><span class="line">	xorq %rax,%rax           #result&#x3D;0</span><br><span class="line">    irmovq $8,%r9</span><br><span class="line">    irmovq $1,%r10</span><br><span class="line">    jmp test</span><br><span class="line">loop:</span><br><span class="line">    mrmovq (%rdi),%rbx        #long val &#x3D; *src;</span><br><span class="line">    addq %r9,%rdi            #src++;</span><br><span class="line">    rmmovq %rbx,(%rsi)        #*dest &#x3D; val;</span><br><span class="line">    addq %r9,%rsi            #dest++;</span><br><span class="line">    xorq %rbx,%rax            #update checksum</span><br><span class="line">    subq %r10,%rdx           #len--</span><br><span class="line">test:</span><br><span class="line">    andq %rdx,%rdx  #set CC</span><br><span class="line">    jne loop        #Stop when len &#x3D; 0</span><br><span class="line">    popq %r10</span><br><span class="line">    popq %r9</span><br><span class="line">    popq %rbx</span><br><span class="line">	ret                         </span><br><span class="line"></span><br><span class="line"># Stack starts here and grows to lower addresses.</span><br><span class="line">	.pos 0x200</span><br><span class="line">stack:</span><br><span class="line"></span><br></pre></td></tr></table></figure>










<p>pa就看的我死去活来了。。。pb pc真的有空补吧人都要没了</p>

    </div>

    
    
    

      <footer class="post-footer">

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/diazang/2021/04/28/csapp-buflab/" rel="prev" title="csapp_buflab">
      <i class="fa fa-chevron-left"></i> csapp_buflab
    </a></div>
      <div class="post-nav-item">
    <a href="/diazang/2021/05/06/bank/" rel="next" title="bank">
      bank <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#PART-A"><span class="nav-number">1.</span> <span class="nav-text">PART A</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#sum-list"><span class="nav-number">1.1.</span> <span class="nav-text">sum_list</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#sum-list-ys"><span class="nav-number">1.1.0.1.</span> <span class="nav-text">sum_list.ys</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#rsum-list"><span class="nav-number">1.2.</span> <span class="nav-text">rsum_list</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#rsum-list-ys"><span class="nav-number">1.2.0.1.</span> <span class="nav-text">rsum_list.ys</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#copy-block"><span class="nav-number">1.3.</span> <span class="nav-text">copy_block</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#copy-block-sy"><span class="nav-number">1.3.0.1.</span> <span class="nav-text">copy_block.sy</span></a></li></ol></li></ol></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="H.R.P"
      src="https://www.hualigs.cn/image/6015786be4309.jpg">
  <p class="site-author-name" itemprop="name">H.R.P</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/diazang/archives/">
        
          <span class="site-state-item-count">38</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
  </nav>
</div>



      </div>
        <div class="back-to-top motion-element">
          <i class="fa fa-arrow-up"></i>
          <span>0%</span>
        </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        <!-- 用下面的符号注释，注释代码用下面括号括起来 -->
<!-- -->

<!-- 







-->


        








      </div>
    </footer>
  </div>

  
  <script src="/diazang/lib/anime.min.js"></script>
  <script src="/diazang/lib/velocity/velocity.min.js"></script>
  <script src="/diazang/lib/velocity/velocity.ui.min.js"></script>

<script src="/diazang/js/utils.js"></script>

<script src="/diazang/js/motion.js"></script>


<script src="/diazang/js/schemes/pisces.js"></script>


<script src="/diazang/js/next-boot.js"></script>




  




  
<script src="/diazang/js/local-search.js"></script>













  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : false,
      appId      : 'g8R6OK66Q2xJiQieSaxzFqVA-gzGzoHsz',
      appKey     : 'V9mmkUCmucvukcz6LwkONqXa',
      placeholder: "Just go go",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : false,
      lang       : '' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

</body>
</html>
<a href="http://jue-xian.gitee.io/diazang"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#70B7FD; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
<!-- 动态背景 -->
<script type="text/javascript" src="//cdn.bootcss.com/canvas-nest.js/1.0.0/canvas-nest.min.js"></script>
<!-- 页面点击小红心 -->
<script type="text/javascript" src="/js/src/clicklove.js"></script>


